package cn.dlc.com.service;

import cn.dlc.com.entity.SgxkBjxx;
import cn.dlc.com.entity.SgxkGcXX;
import cn.dlc.com.mapper.BjxxMapper;
import cn.dlc.com.mapper.GcxxMapper;
import cn.dlc.com.mapper.JsdwMapper;
import cn.dlc.com.util.PostUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: dlc
 * @Date: 2022/4/26 - 13:20
 */
@Service
public class BjxxServiceImpl extends ServiceImpl<BjxxMapper, SgxkBjxx> implements IBJxxService {

    public void set(String url, String params){

        try {

            HttpEntity entity = PostUtils.createRequestPost(url, params);

            String result= EntityUtils.toString(entity);
            JSONObject jsonObject = JSONObject.parseObject(result);

            JSONObject data = jsonObject.getJSONObject("data");

            JSONArray resultlist = data.getJSONArray("resultlist");

            List<SgxkBjxx> bjxxList = resultlist.toJavaList(SgxkBjxx.class);

            this.saveBatch(bjxxList);

            System.out.println("end----");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
